import os


def rename_files_in_folder(folder_path, new_name_prefix):
    # 获取文件夹中的文件列表
    files = os.listdir(folder_path)

    # 遍历文件列表并重命名
    for index, filename in enumerate(files):
        # 构建新的文件名
        new_name = f"{new_name_prefix}_({index + 1}).jpg"
        # print(filename)
        # 获取文件的原始路径和新路径
        old_file_path = os.path.join(folder_path, filename)
        new_file_path = os.path.join(folder_path, new_name)
        # print(new_name)
        # print(old_file_path)
        # print(new_file_path)
        # 重命名文件
        os.rename(old_file_path, new_file_path)



# 使用示例
folder_path = r"D:\CodeData\Code\Python\pythonCode\GrammerStudy\utils\images\4_20240314-1"  # 请替换为实际文件夹路径
new_name_prefix = input("prefix: ")  # 请替换为实际新文件名前缀
rename_files_in_folder(folder_path, new_name_prefix)
